﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.IO;

namespace WindowsFormsApplication9
{
    class Nunit
    {
        string[] extension = { ".csv", ".xml", ".json", ".yaml" };
        AnimalList alist = new AnimalList();

        private void INIT(int i)
        {
            alist.Clear();
            if (i > 0)
            {
                alist.Clear();
                Animal a = new Animal();
                a.Age = 11;
                a.IsMale = true;
                a.Name = Convert.ToString(11111);
                alist.Add(a);
            }
            if (i > 1)
            {
                Cat c = new Cat();
                c.Age = 22;
                c.IsMale = false;
                c.Name = Convert.ToString(22222);
                c.Color = "White";
                alist.Add(c);
            }
        }
        //------------------------------------------
        object[] TestData =
        {
        new TestCaseData(0, 0),
        new TestCaseData(1, 0),
        new TestCaseData(2, 0),
        new TestCaseData(0, 1),
        new TestCaseData(1, 1),
        new TestCaseData(2, 1),
        new TestCaseData(0, 2),
        new TestCaseData(1, 2),
        new TestCaseData(2, 2),
        new TestCaseData(0, 3),
        new TestCaseData(1, 3),
        new TestCaseData(2, 3),
        };

        [Test]
        [TestCaseSource("TestData")]
        public void ParameterizedTest(int N, int j)
        {
            INIT(N);
            string path = @"C:\UT\test" + extension[j];

            alist.save(path);
            string[] actual = File.ReadAllLines(@"C:\UT\test" + extension[j]);
            string[] expected = File.ReadAllLines(@"C:\UT\expected" + Convert.ToString(N) + extension[j]);

            Assert.AreEqual(expected.Length, actual.Length);
            for (int i = 0; i < expected.Length; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }


        [Test]
        [TestCaseSource("TestData")]
        public void Test_xList_LoadMethod(int N, int j)
        {
            INIT(N);
            string fileName = @"C:\UT\expected" + Convert.ToString(N) + extension[j];

            AnimalList actual = new AnimalList();
            actual.load(fileName);
            Assert.AreEqual(alist.Count, actual.Count);
            for (int i = 0; i < alist.Count; i++)
            {
                Assert.AreSame(((Animal)alist[i]).Type, ((Animal)actual[i]).Type);
                Assert.AreEqual(0, ((Animal)alist[i]).CompareTo(actual[i]));
            }

        }


    }
}
